﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>设置报表查询条件</title>
    <link href="../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/QueryString.js"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js"></script>
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" />
    <script language="javascript" type="text/javascript">

        //页面启动函数.
        $(function () {

            $("#Msg").html("<img src=../../../Img/loading.gif />&nbsp;正在加载,请稍后......");

            InitPage();

            $("#Msg").html("");

        });

        function InitPage() {
            if (GetQueryString("RptNo").indexOf("RptMyDept") == -1)
                $("#LevelDiv").hide();

            var checkBoxIDs = GetSelectedCheckIDs();
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_RptDfine");
            handler.AddPara("RptNo", GetQueryString("RptNo"));
            handler.AddPara("FK_Flow", GetQueryString("FK_Flow"));
            var data = handler.DoMethodReturnString("S5SearchCond_Init");

            if (data.indexOf("@") == 0) {
                alert(data);
                return;
            }
            var jsData = JSON.parse(data);

            var md = jsData["Main"][0]; //主表数据.
            md = new Entity("BP.Sys.MapData", md);

            var Sys_MapAttr = jsData["Sys_MapAttr"]; //所有的列.
            var Sys_MapAttrOfDate = jsData["Sys_MapAttrOfDate"]; //日期列表.
            //关键字查询.
            var isSearchKey = md.GetPara("IsSearchKey") == "1" ? true : false;
            document.getElementById("CB_Key_0").checked = isSearchKey;

            document.getElementById("CB_Key_1").checked = isSearchKey == true ? false : true;

            document.getElementById("CB_NextLeavel").checked = (md.AtPara.indexOf("@IsSearchNextLeavel=1@") != -1);

            var StringSearchKeys = md.GetPara("StringSearchKeys");
            var RptSearchKeys = md.GetPara("RptSearchKeys");
            //  var dtSearchWay = md.GetPara("DTSearchWay");
            var DTSearchKey = md.GetPara("DTSearchKey");

            //绑定外键字段.
            var count = 0;
            var disabled = "";
            if (isSearchKey == true)
                disabled = " disabled=disabled ";
            for (var i = 0, length = Sys_MapAttr.length; i < length; i++) {
                var attr = Sys_MapAttr[i], flag = false;
                //文本字段
                if (attr.MyDataType == 1 && attr.UIContralType == 0) {
                    count++;
                    flag = false;
                    if (StringSearchKeys) {
                        flag = (StringSearchKeys.indexOf("*" + attr.KeyOfEn + ",") != -1);
                    }
                    $("#StringKeys").append("<input type='checkbox' " + disabled + (flag ? " checked = 'checked'" : "") + " id='" + attr.KeyOfEn + "'  data-name='" + attr.Name + "'/><label for='" + attr.KeyOfEn + "' >" + attr.Name + "(" + attr.KeyOfEn + ")</label><br/>");
                    continue;
                }

                if (attr.UIContralType == 1 || attr.UIContralType == 3) {
                } else
                    continue;

                flag == false;
                if (RptSearchKeys) {
                    flag = (RptSearchKeys.indexOf("*" + attr.KeyOfEn + "*") != -1);
                }
                $("#FKeys").append("<input type='checkbox' " + (flag ? "checked = 'checked'" : "") + " id='" + attr.KeyOfEn + "' /><label for='" + attr.KeyOfEn + "' >" + attr.Name + "(" + attr.KeyOfEn + ")</label></br>");
            }

            $("#DDL_DTSearchWay").val(md.GetPara("DTSearchWay"));


            //绑定日期下拉框.
            if (Sys_MapAttrOfDate != null) {
                GenerBindDDL("DDL_DTSearchKey", Sys_MapAttrOfDate, "KeyOfEn", "Name", md.GetPara("DTSearchKey"));
            }

            $("#DDL_DTSearchKey").val(md.GetPara("DTSearchKey"));

            //alert(md.GetPara("DTSearchKey"));
            return;
        }

        function Save() {

            $("#Btn_Save").text("正在保存请稍候....");

            var FK_Flow = GetQueryString("FK_Flow");
            var RptNo = GetQueryString("RptNo");
            var isSearchKey = document.getElementById("CB_Key_0").checked ? 1 : 0;
            //DTSearchWay = document.getElementById("DDL_DTSearchWay").value,
            //DTSearchKey = document.getElementById("DDL_DTSearchKey").value,
            var Fields = "";
            //获得外键.
            var oChecks = document.getElementById("FKeys").getElementsByTagName("input");
            for (var i = 0, len = oChecks.length; i < len; i++) {
                var item = oChecks[i];
                if (item.checked) {
                    Fields += "*" + item.id;
                }
            }

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_RptDfine");
            handler.AddPara("RptNo", GetQueryString("RptNo"));
            handler.AddPara("FK_Flow", GetQueryString("FK_Flow"));

            handler.AddPara("Fields", Fields);
            handler.AddPara("IsSearchKey", isSearchKey); //是否按照关键字查询?

            handler.AddPara("DTSearchWay", $("#DDL_DTSearchWay").val()); //日期查询方式?
            handler.AddPara("DTSearchKey", $("#DDL_DTSearchKey").val()); //日期字段

            //alert($("#DDL_DTSearchKey").val());


            handler.AddPara("IsSearchNextLeavel", document.getElementById("CB_NextLeavel").checked ? 1 : 0);

            fields = "";
            if (document.getElementById("CB_Key_1").checked == 1) {
                oChecks = document.getElementById("StringKeys").getElementsByTagName("input");
                for (var i = 0, len = oChecks.length; i < len; i++) {
                    var item = oChecks[i];
                    if (item.checked) {
                        fields += "*" + item.id + "," + item.getAttribute("data-name");
                    }
                }
                if (fields != "")
                    fields = fields + "*";
            }

            handler.AddPara("StringSearchKeys", fields);

            var data = handler.DoMethodReturnString("S5SearchCond_Save");

            // var url = "S5SearchCond.htm?FK_Flow=004&RptNo=ND4RptMy&s=0.16464278561650458";
            //alert(url);
            //window.location.href = url;
            window.location.href = window.location.href;

        }

        //获得所有的checkbox 的id组成一个string用逗号分开, 以方便后台接受的值保存.
        function GetSelectedCheckIDs() {

            var checkBoxIDs = "";
            var arrObj = document.getElementsByTagName("input");

            for (var i = 0, len = arrObj.length; i < len; i++) {

                if (arrObj[i].type == 'checkbox') {
                    if (arrObj[i].checked)
                        checkBoxIDs += arrObj[i].id + ',';
                }
            }
            return checkBoxIDs;
        }

        function changeStringKeysState(val) {
            if (val == 0) {
                $("#StringKeys input[type=checkbox]").attr("disabled", 'disabled');
                $("#StringKeys input[type=checkbox]").removeAttr("checked");
            }
            if (val == 1) {
                $("#StringKeys input[type=checkbox]").removeAttr("disabled");
            }
        }
    </script>
</head>
<body>


    <h3>设置报表查询条件 </h3>

    <div id="Msg"></div>

    <fieldset>
        <legend>字段String类型查询 </legend>
        <label for="CB_Key_0"><input type="radio" name="CB_Key" id="CB_Key_0" value="0" onchange="changeStringKeysState(this.value)" />是否增加关键字查询</label><span style="margin-left:10px">----关键字查询是接受用户输入一个关键字，在整个报表的显示列中使用like查询(外键、枚举、数值类型的除外))</span><br />
        <label for="CB_Key_1"><input type="radio" name="CB_Key" id="CB_Key_1" value="1" onchange="changeStringKeysState(this.value)" />是否增加特定字段的查询</label><span style="margin-left:10px">----选择特定字段，在报表中根据like模糊查询</span><br />
        <div id="StringKeys" style="margin-left:15px"> </div>

        <legend> 外键与枚举类型 </legend>
        <div id="FKeys"></div>

        <legend> 时间段 </legend>
        对数据按照时间段进行查询，比如：按流程的发起时间，在指定时间段内进行查询。<br />
        选择方式：<select name="DDL_DTSearchWay" id="DDL_DTSearchWay">
            <option selected="selected" value="0">不启用</option>
            <option value="1">按日期</option>
            <option value="2">按日期时间</option>
        </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;字段：<select name="DDL_DTSearchKey"
                                                                id="DDL_DTSearchKey">
            <!--<option value="FlowEnderRDT">FlowEnderRDT 结束时间</option>
            <option selected="selected" value="FlowStartRDT">FlowStartRDT 发起时间</option>-->
        </select>


        <div style='width: 100%' id="LevelDiv">
            <legend> 是否查询子级部门 </legend>
            子级部门查询是查询这个子级部门的下一级<br />
            <input id="CB_NextLeavel" type="checkbox" name="CB_NextLeavel" /><label for="CB_NextLeavel">是否查询子级部门</label>
        </div>

    </fieldset>


    <br />
    <br />

    <button id="Btn_Save" onclick="Save()">保存 </button>


</body>
</html>
